package com.his.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import com.his.dao.jpa.LfqPharmacyDetailsJpaDao;
import com.his.pojos.HisPharmacydetail;
import com.his.vo.LfqPharmacydetailVo;

@Service
@Transactional
public class LfqPharmacydetailServices {
    @Autowired
	private LfqPharmacyDetailsJpaDao pharmacyDetailsJpaDao;
    
    public Map<String, Object> selectPharmacydetailVo(int page,int rows){
    	PageRequest pageRequest=new PageRequest(page-1, rows);
    	List<LfqPharmacydetailVo> list=pharmacyDetailsJpaDao.selectPharmacydetailVo(pageRequest);
    	Map<String, Object> map=new HashMap<>();
    	map.put("total", pharmacyDetailsJpaDao.count());
    	map.put("rows", list);
    	return map;
    }
    
    public Map<String, Object> selectPharmacydetailVoXiYao(int page,int rows){
    	PageRequest pageRequest=new PageRequest(page-1, rows);
    	List<LfqPharmacydetailVo> list=pharmacyDetailsJpaDao.selectPharmacydetailVoXiYao(pageRequest);
    	Map<String, Object> map=new HashMap<>();
    	map.put("total", pharmacyDetailsJpaDao.selectPharmacydetailVoXiYaoSize());
    	map.put("rows", list);
    	return map;
    }
    
    public Map<String, Object> selectPharmacydetailVoZhongYao(int page,int rows){
    	PageRequest pageRequest=new PageRequest(page-1, rows);
    	List<LfqPharmacydetailVo> list=pharmacyDetailsJpaDao.selectPharmacydetailVoZhongYao(pageRequest);
    	Map<String, Object> map=new HashMap<>();
    	map.put("total", pharmacyDetailsJpaDao.selectPharmacydetailVoZhongYaoSize());
    	map.put("rows", list);
    	return map;
    }
    
    public Map<String, Object> selectPharmacydetailVoXiYaoLikeCpname(int page, int rows, String cpName){
    	PageRequest pageRequest=new PageRequest(page-1, rows);
    	List<LfqPharmacydetailVo> list=pharmacyDetailsJpaDao.selectPharmacydetailVoXiYaoLikeCpname(pageRequest,cpName);
    	Map<String, Object> map=new HashMap<>();
    	map.put("total", pharmacyDetailsJpaDao.selectPharmacydetailVoXiYaoLikeCpnameSize(cpName));
    	map.put("rows", list);
    	return map;
    }
    
    public Map<String, Object> selectPharmacydetailVoZhongYaoLikeCpname(int page, int rows, String cpName){
    	PageRequest pageRequest=new PageRequest(page-1, rows);
    	List<LfqPharmacydetailVo> list=pharmacyDetailsJpaDao.selectPharmacydetailVoZhongYaoLikeCpName(pageRequest,cpName);
    	Map<String, Object> map=new HashMap<>();
    	map.put("total", pharmacyDetailsJpaDao.selectPharmacydetailVoZhongYaoLikeCpNameSize(cpName));
    	map.put("rows", list);
    	return map;
    }
    
    public LfqPharmacydetailVo updatePharmacydetailByYgxqNo(long ygxqNo){
    	return pharmacyDetailsJpaDao.updatePharmacydetailByYgxqNo(ygxqNo);
    }
    
    public void submitPharmacydetailEditXiyao(LfqPharmacydetailVo pharmacydetailVo){
    	HisPharmacydetail pharmacydetail=pharmacyDetailsJpaDao.selectPharmacydetailById(pharmacydetailVo.getYgxqNo());
    	pharmacydetail.setYgxqSaleprice(pharmacydetailVo.getYgxqSaleprice());
    	pharmacydetail.setYfxqUnit(pharmacydetailVo.getYfxqUnit());
    	pharmacyDetailsJpaDao.save(pharmacydetail);
    }
	
}
